Use tensor in window_reverse
to avoid precision issue
#617
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在
window_reverse
里将window_size
转换为 Tensor,windows.shape[0]
、H
、W
在动转静下,因为是动态 shape,所以都是 Tensor,而window_size
是 scalar,会触发 scale OP,x / n
会转为scale(x, 1/n)
,这会导致精度问题,进而导致计算结果出错一个简单的复现样例:
暂时避免触发 scale OP,将
window_size
转为 Tensor 以触发elementwise_div
,未来可以考虑加一个scale_div
OP,让x / n
转为scale_div(x, n)
以避免精度问题(等之后 @gouzil 有空试试?)该问题一直存在,只是之前的类型提升是向左 cast 隐藏了这点而已,3.0-beta 改了类型提升机制暴露了这点
另外还修改了下 predict 脚本里因为类型提升机制修改挂掉的问题,加了手动 cast